<%@ page language="java" pageEncoding="utf-8"%>
<%@ taglib prefix="s" uri="/struts-tags" %>

<!DOCTYPE html>
<html>
<head>
	<title>我是雪花妹（<s:property value='mmDetail.nickname' />）</title>
	<meta name="viewport" content="width=device-width,initial-scale=1.0,minimum-scale=1.0,maximum-scale=1.0,uer-scalable=no">
	<!-- Bootstrap -->
	<link rel="stylesheet" href="../bootstrap/css/bootstrap.css">
	<link rel="stylesheet" href="../font-awesome/css/font-awesome.min.css">
	<script src="http://cdn.bootcss.com/jquery/2.0.3/jquery.min.js"></script>
	<script src="http://cdn.bootcss.com/bootstrap/3.1.1/js/bootstrap.min.js"></script>
	<script src="../js/jquery.form.min.js"></script>
	<style type="text/css">
	.mlist-title {height:40px; font-size:14px; line-height:40px; background-color:#990066; text-indent:10px; color:#fff;}
	</style>
</head>
<body>
	<div class="mlist-title">未处理的订座信息</div>

	<div class="bs-example">
	<table class="table table-condensed">
		<thead>
			<th>订座时间</th>
			<th>订座信息</th>
			<th>状态</th>
			<th></th>
		</thead>
		<tbody>
			<s:iterator value="bookList" id="book">
			<tr>
				<td>
					<s:date name="#book.createTime" format="dd日HH:mm" />
				</td>
				<td>
					<s:property value='#book.loca.poi' /><br/>
				  	就餐：<s:property value='#book.custNum' />人<br/>
				  	时间：<s:property value='#book.arriTime' /><br/>
				  	称呼：<s:property value='#book.custName' /><br/>
				  	电话：<s:property value='#book.custPhone' />
				</td>
				<td>
					<small>
					<s:if test="#book.status==0">预订中</s:if>
					<s:elseif test="#book.status==1">成功</s:elseif>
					<s:elseif test="#book.status==2">失败</s:elseif>
					<s:elseif test="#book.status==3">取消</s:elseif>
					<s:elseif test="#book.status==4">删除</s:elseif>
					<s:else>-</s:else>
					</small>
				</td>
				<td>
					<input type="hidden" id="book_mmid_<s:property value='#book.id' />" value="<s:property value='#book.mmid' />" />
					<input type="hidden" id="book_openId_<s:property value='#book.id' />" value="<s:property value='#book.openId' />" />
					<input type="hidden" id="book_loca_poi_<s:property value='#book.id' />" value="<s:property value='#book.loca.poi' />" />
					<button type="button" id="btn_opt_<s:property value='#book.id' />" class="btn btn-success btn-sm" onclick="opt(<s:property value='#book.id' />)">操作</button>
				</td>
			</tr>
			</s:iterator>
		</tbody>
	</table>
	</div>

<!-- Modal -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
        <h4 class="modal-title" id="myModalLabel">处理预订信息</h4>
      </div>
      <div class="modal-body">
        <form id="frmBookMsg" role="form">
        <div class="form-group">
        <label for="inputMessage">留言</label>
        <input type="text" name="book.message" class="form-control" id="inputMessage">
        <s:hidden key="book.id"></s:hidden>
		<s:hidden key="book.mmid"></s:hidden>
		<s:hidden key="book.openId"></s:hidden>
		<s:hidden key="book.loca.poi"></s:hidden>
        </div>
        </form>
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default" onclick="bookOpt('cancel')">取消预订</button>
        <button type="button" class="btn btn-primary" onclick="bookOpt('success')">完成</button>
      </div>
    </div><!-- /.modal-content -->
  </div><!-- /.modal-dialog -->
</div><!-- /.modal -->


<script type="text/javascript">

function opt(id) {
	
	var mmid = $("#book_mmid_"+id).val();
	var openId = $("#book_openId_"+id).val();
	var poi = $("#book_loca_poi_"+id).val();
	
	$("#book_id").val(id);
	$("#book_mmid").val(mmid);
	$("#book_openId").val(openId);
	$("#book_loca_poi").val(poi);
	
	$("#myModal").modal("show");
}

function bookOpt(type) {
	
	var msg = $("#inputMessage").val();
	if (msg.length==0) {
		alert("请填写留言的内容");
		return;
	}
	
	var id = $("#book_id").val();
	var posturl = "";
	if (type == "success") {
		posturl = "./booking_success";
	} else {
		posturl = "./booking_cancel";
	}
	
	var params=$("#frmBookMsg").formSerialize();
	params = decodeURIComponent(params,true);
	
	$.ajax({
		type:"POST",
		url: posturl,
		dataType: "json",
		data: params,
		async: false,
		success: function(data) {
			if (data.result == "success") {
				alert("操作成功");
				$("#btn_opt_"+id).addClass("disabled");
			} else {
				alert("抱歉，我们遇到一点问题，请稍后再试。");
			}
		},
		error: function(err) {
			alert("抱歉，我们遇到一点问题，请稍后再试。");
		}
	});
	
	$("#myModal").modal("hide");
}
</script>
	
</body>
</html>
